package com.zbs.test.test;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import io.webfolder.cdp.Launcher;
import io.webfolder.cdp.session.Session;
import io.webfolder.cdp.session.SessionFactory;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Comment;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.junit.Test;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * @author
 * @since 2018/12/13
 */
public class CodeGenerator {

    @Test
    public void run() {
        String json = "[\"福建省\",\"福州市\",\"仓山区\"] ";
        System.out.println(String.join("", JSON.parseArray(json, String.class)));

        String str = "[\"福建省\",\"福州市\",\"仓山区\"]";
        Pattern p = Pattern.compile("[\\u4e00-\\u9fa5]+");
        Matcher m = p.matcher(str);
        StringBuilder result = new StringBuilder();
        while (m.find()) {
            result.append(m.group());
        }
        System.out.println(result);
    }

    @Test
    public void test2() {
        String projectPath = System.getProperty("user.dir");
        FastAutoGenerator
                .create("jdbc:mysql://127.0.0.1:3306/basemal_line_up?useUnicode=true&characterEncoding=utf8&useSSL=false",
                        "root",
                        "123456")
                .globalConfig(builder -> {
                    builder.author("Zbs") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir(projectPath + "/src/main/java")

                    ; // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.yiga.gruul.line.up") // 设置父包名
                            .moduleName("service") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, projectPath + "/src/main/resources/mapper")); // 设置mapperXml生成路径
                })
                .templateConfig(temp -> {
                    temp.entity("/templates_swagger3/my_entity.java")
                            .controller("/templates_swagger3/my_controller.java")
                            .serviceImpl("/templates_swagger3/my_serviceImpl.java")
                            .mapper("/templates_swagger3/my_mapper.java");
                })
                .strategyConfig(builder -> {
                    builder.addInclude(
                                    "lu_line_up_pool",
                                    "lu_line_up_queue"
                            ) // 设置需要生成的表名
//                            .addTablePrefix()// 设置过滤表前缀
                            .controllerBuilder()
                            .enableHyphenStyle()
                            .enableRestStyle()
                            .serviceBuilder()
                            .formatServiceFileName("%sService")
//                            .entityBuilder()
                            .entityBuilder()
                            .enableLombok()
                            .idType(IdType.ASSIGN_ID)
//                            .enableActiveRecord()
//                            .enableChainModel()

                    ;
                })
                .execute();
    }

    @Test
    public void test() {
        String projectPath = System.getProperty("user.dir");
        FastAutoGenerator
                .create("jdbc:mysql://192.168.3.81:3306/framework_v2?useUnicode=true&characterEncoding=utf8&useSSL=false",
                        "root",
                        "123456")
//                .create("jdbc:mysql://116.196.69.57:8080/bida-crm-jd-dev?useUnicode=true&characterEncoding=utf8&useSSL=false",
//                        "jd_root",
//                        "ZdwZ_xvD*3")
//                .create("jdbc:mysql://127.0.0.1:3307/gulimall_wms?useUnicode=true&characterEncoding=utf8&useSSL=false",
//                        "root",
//                        "123456")
//                .create("jdbc:oscar://10.124.161.3:2003/osrdb",
//                        "E9",
//                        "gzszf@2021@weaver")
                .globalConfig(builder -> {
                    builder.author("Zbs") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir(projectPath + "/src/main/java")

                    ; // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.zbs.framework.core") // 设置父包名
//                    builder.parent("com.bida.crm.cloud.common") // 设置父包名
//                    builder.parent("com.zbs.activity") // 设置父包名
                            .moduleName("dept") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, projectPath + "/src/main/resources/mapper")); // 设置mapperXml生成路径
                })
                .templateConfig(temp -> {
                    temp.entity("/templates_swagger3_swagger3/my_entity.java")
                            .controller("/templates_swagger3_swagger3/my_controller.java")
                            .serviceImpl("/templates_swagger3_swagger3/my_serviceImpl.java")
                            .mapper("/templates_swagger3_swagger3/my_mapper.java");
                })
                .strategyConfig(builder -> {
                    builder.addInclude(
                            "dept_org_role",
                            "dept_org_user",
                            "dept_organization",
                            "dept_post",
                            "dept_post_role",
                            "dept_user_post"
                            ) // 设置需要生成的表名
                            .addTablePrefix("mnt_")// 设置过滤表前缀
                            .controllerBuilder()
                            .enableHyphenStyle()
                            .enableRestStyle()
                            .serviceBuilder()
                            .formatServiceFileName("%sService")
//                            .entityBuilder()
                            .entityBuilder()

                            .enableLombok()
                            .idType(IdType.ASSIGN_ID)
                            .enableActiveRecord()
//                            .enableChainModel()

                    ;
                })
                .execute();
    }

}